package com.ndp.fb.walle.model.vo;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Jacky on 2014/10/15.
 */
@Setter
@Getter
@NoArgsConstructor
public class RespModel implements Serializable {

    private static final long serialVersionUID = -6571902160851229352L;
    private String flag = "fail";
    private String msg = "";
    private String errorCode = "";
    private Object data;
    private String Resp_Flag_Success = "success";
    private String Resp_Flag_Fail = "fail";

    public RespModel(String flag) {
        this.flag = flag;
    }

    public RespModel(Object data) {
        this.setFlag(Resp_Flag_Success);
        this.data = data;
    }

    public RespModel(String errorCode, String msg) {
        this.setFlag(Resp_Flag_Fail);
        this.errorCode = errorCode;
        this.msg = msg;
    }

    public RespModel(String flag, Object data) {
        this.flag = flag;
        this.data = data;
    }

    public RespModel(String flag, String msg, String errorCode) {
        this.flag = flag;
        this.msg = msg;
        this.errorCode = errorCode;
    }

    public void appendData(Object o) {
        if (data == null) {
            setData(o);
            return;
        }
        if (data instanceof List) {
            ((List) data).add(o);
        } else {
            List<Object> list = new ArrayList<Object>();
            list.add(data);
            list.add(o);
            setData(list);
        }
    }

}
